package net.esj.tree;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import net.esj.tree.service.TreeService;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.support.AbstractMessageSource;

public class TreeConfigurer {

	public static final String VIEW_MODULE_TREE = "_tree";//树状结构
	public static final String VIEW_MODULE_MULTI = "_multi";//多层次选择
	
	private Map<String,Object> modules = new HashMap<String,Object>();

	private Map<String,TreeResourceBundleMessageSource> messageSources = new HashMap<String, TreeResourceBundleMessageSource>();
	
	@PostConstruct
	private void initConfig(){
		for(String key : modules.keySet()){
			TreeResourceBundleMessageSource messageSource = new TreeResourceBundleMessageSource(key);
			messageSources.put(key, messageSource);
		}
	}
	
	public void setModules(Map<String, Object> modules) {
		this.modules = modules;
	}
	
	public TreeService getService(String key){
		Object o = modules.get(key);
		if(o!=null && o instanceof TreeService){
			return (TreeService)o;
		}
		throw new NoSuchBeanDefinitionException("no bean mapping for key:"+key+" in treeConfigurer");
	}
	
	public AbstractMessageSource getMessageSource(String key){
		return messageSources.get(key);
	}
	
}
